package edu.zut.cs.network;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Menu {
	@SuppressWarnings("resource")
	Scanner in=new Scanner(System.in);
	Map<String,Double> cmap=new HashMap<String,Double>(); 
	Map<String, String> m=new HashMap<String, String>();
	public boolean check() {
		System.out.println("输入用户名：");
		String name;
		name=in.next();
		System.out.println("输入密码：");
		String pwd;
		pwd=in.next();
		for(String key:m.keySet()) {
			if(name.equals(key)) {
				if(pwd.equals(m.get(key))) {
					System.out.println("登陆成功！");
					return true;
				}
			}
		}
		System.out.println("用户名密码错误！");
		return false;
	}
	public void menu(){
		System.out.println("欢迎来到*中工银行*");
		System.out.println(" ->1.查询余额");
		System.out.println(" ->2.存款");
		System.out.println(" ->3.取款");
		System.out.println(" ->0.退出");
	}
	public void chunkuan(String name,double a) {
		if(cmap.size()==0) {
			cmap.put(name, +a);
		}
		else {
			for(String key:cmap.keySet()) {
				if(name.equals(key)) {
					cmap.put(name, cmap.get(name)+a);
					}
				}
		}
		System.out.println("用户"+name+"当前余额："+cmap.get(name)+"元");
	}
	public void find() {
		System.out.println("输入查找的用户名：");
		String name=in.next();
		for(String n:cmap.keySet()) {
			if(name.equals(n)) {
				System.out.println("用户"+name+"当前余额："+cmap.get(name)+"元");
			}
		}
	}
	public void qukuan(String name,double a) {
		if(cmap.size()==0) {
			cmap.put(name, +a);
		}
		else {
			for(String key:cmap.keySet()) {
				if(name.equals(key)) {
					cmap.put(name, cmap.get(name)-a);
					}
				}
		}
		System.out.println("用户"+name+"当前余额："+cmap.get(name)+"元");
	}
	public void zhuce() {
		System.out.println("****注册页面****");
		System.out.println("输入用户名：");
		String name=new String();
		name=in.nextLine();
		System.out.println("输入密码：");
		String pwd=new String();
		pwd=in.nextLine();				
		m.put(name, pwd);
		cmap.put(name, 0.0);
		System.out.println("已注册成功！当前余额："+cmap.get(name)+"元");
	}
	public void choose() {		
			menu();		
			while(true) {
				System.out.println("选择你的选项：");
				int key=in.nextInt();
				switch (key) {					
				case 1:
					find();
					break;
				case 2:{
					System.out.print("输入用户名：");
					String name=in.next();		
					System.out.print("输入存款金额：");
					double cash=in.nextDouble();
					chunkuan(name, cash);
					}break;
				case 3:{
					System.out.print("输入用户名：");
					String na=in.next();
					System.out.print("输入取款金额：");
					double c=in.nextDouble();
					qukuan(na,c);
					}break;
				
				}
				if(key==0) {
					System.out.println("您已退出程序！");
					break;
				}
		}
	}
}
